<template>
  <div class="container">
    <div class="action">
      <!-- <el-button size="mini" type="primary" icon="el-icon-plus" @click="toAdd"
        >新建</el-button
      > -->
    </div>
    <div class="list">
      <baseTable :tableSetting="tableSetting" ref="tableParam"></baseTable>
    </div>
    <dialogPublic
      width="600px"
      :title="title"
      :show.sync="show"
      v-if="show"
      @doSubmit="doSubmit"
      @doClose="() => (show = false)"
    >
      <editForm
        class="form"
        :formConfig="basicConfig"
        ref="basicForm"
        :formData="basicFormData"
      ></editForm>
    </dialogPublic>
  </div>
</template>

<script>
import {
  addInfo,
  deleteInfo,
  updateInfo,
  queryList,
} from "@/api/businessConfigurationManagement/defectLevelConfiguration.js";
export default {
  data() {
    return {
      title: "", // 弹框标题
      show: false, // 弹框显示
      tableSetting: {
        indexShow: true, // 序号显示
        maxHeight: 600,
        column: [
          {
            label: "缺陷等级",
            prop: "level",
            required: true,
            disabled: true,
            formatter: (row) => {
              let types = this.$store.getters["dirtData"]("defect_order_level");
              let val = row.level;
              let obj = types.find((i) => i.value == val);
              return obj ? obj.label : val;
            },
          },
          {
            label: "消缺期限（天）",
            prop: "termSection",
            required: true,
          },
          {
            label: "操作",
            type: "button",
            scopeType: "textButton",
            width: "240px",
            buttonArr: [
              {
                text: "编辑",
                icon: "icon-a-xiugaibianji",
                isShow: (row) => {
                  return true;
                },
                methods: (row) => {
                  this.basicFormData = row;
                  this.title = "编辑";
                  this.show = true;
                },
              },
              // {
              //   text: "删除",
              //   icon: "el-icon-delete-solid",
              //   isShow: (row) => {
              //     return true;
              //   },
              //   methods: (row) => {
              //     this.$confirm("确定要删除这条数据吗", "提示", {
              //       confirmButtonText: "确定",
              //       cancelButtonText: "取消",
              //       type: "warning",
              //     })
              //       .then(() => {
              //         this.delete(row.id);
              //       })
              //       .catch(() => {});
              //   },
              // },
            ],
          },
        ],
        data: [],
      },
      // 弹框信息表单
      basicConfig: {
        labelWidth: "164px",
        itemArr: [
          {
            label: "缺陷等级",
            prop: "level",
            type: "select",
            required: true,
            disabled: true,
            span: 24,
            selectOption: this.$store.getters["dirtData"]("defect_order_level"),
          },
          {
            label: "消缺期限（天）",
            prop: "termSection",
            type: "el-number",
            required: true,
            min: 0,
            placeholder: "请输入",
            span: 24,
          },
          {
            label: "是否必须提交分析报告",
            prop: "firstClass",
            type: "radio",
            required: true,
            span: 24,
            radioOption: [
              { label: "是", value: 1 },
              { label: "否", value: 0 },
            ],
          },
        ],
      },
      // 弹框数据
      basicFormData: {},
    };
  },
  created() {
    this.getTableData();
  },
  methods: {
    // // 新增配置项
    // toAdd() {
    //   this.basicFormData = {};
    //   this.title = "新建";
    //   this.show = true;
    // },
    // 弹框表单提交-新增或修改
    async doSubmit() {
      let actionApi = (params) => {
        return this.title == "新建" ? addInfo(params) : updateInfo(params);
      };
      let data = await this.$refs.basicForm.getFormData();
      await actionApi(data).then((res) => {
        if (res.code == 200) {
          this.show = false;
          // this.$message.success(res.description);
          this.$message.success("保存成功！");
          this.getTableData();
        }
      });
    },
    // //删除配置项详情
    // async delete(id) {
    //   let data = { id: id };
    //   await deleteInfo(data).then((res) => {
    //     if (res.code == 200) {
    //       // this.$message.success(res.description);
    //       this.$message.success("删除成功！");
    //       this.getTableData();
    //     }
    //   });
    // },
    //获取配置项详情
    async getTableData() {
      let { data } = await queryList();
      this.$set(this.tableSetting, "data", data);
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  .action {
    margin: 20px 30px;
    text-align: right;
  }
  .el-button--primary {
    background-color: @kr-main-color;
    border-color: @kr-main-color;
  }
  .list {
    margin: 20px;
  }
  .form {
    width: 450px;
    margin: 0 auto;
    padding: 25px 0;
  }
}
</style>